from proteus import config, Model, Wizard
import os
import csv
import string

#csv file must be inside the same directory of the script.


filepath = os.path.join(os.getcwd(), 'input.csv')
data=[]
f = open(filepath)
csv_f = csv.reader(f)
for row in csv_f:
 data.__iadd__(row)
f.close


config = config.set_trytond('gnuhealth', database_type='postgresql', user='admin', password='admin')
lab = Model.get('gnuhealth.lab')

lab = lab()
lab.create_uid = data[0]
lab.date_requested = data[1]
lab.create_date = data[2]
lab.name = data[3]
lab.requestor = data[4]
lab.date_analysis = data[5]
lab.results = data[6]
lab.write_uid = data[7]
lab.pathologist = data[8]
lab.diagnosis = data[9]
lab.test = data[10]
lab.patient = data[11]
lab.write_date = data[12]
lab.save()


filepath = os.path.join(os.getcwd(), 'input1.csv')
data1=[]
f = open(filepath)
csv_f = csv.reader(f)
for row in csv_f:
 data1.__iadd__(row)
f.close
lab1 = Model.get('gnuhealth.lab.test.critearea')

lab1 = lab1()
lab1.create_uid = data1[0]
lab1.create_date = data1[1]
lab1.name = data1[2]
lab1.sequence = data1[3]
lab1.result_text= data1[4]
lab1.test_type_id = data1[5]
lab1.write_uid = data1[6]
lab1.units= data1[7]
lab1.result = data1[8]
lab1.excluded = data1[9]
lab1.remarks = data1[10]
lab1.gnuhealth_lab_id = data1[11]
lab1.write_date = data1[12]
lab1.warning = data1[13]
lab1.save()

